VERSION 5.00
Begin VB.Form frmLogFound 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "QConsole.log file already in <dir>"
   ClientHeight    =   1800
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   5730
   ControlBox      =   0   'False
   Icon            =   "frmLogFound.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1800
   ScaleWidth      =   5730
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.TextBox txtFileName 
      Height          =   285
      Left            =   3480
      TabIndex        =   7
      Text            =   "<game name>.log"
      Top             =   1320
      Width           =   2175
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "&Cancel"
      Height          =   375
      Left            =   3000
      TabIndex        =   6
      Top             =   840
      Width           =   1215
   End
   Begin VB.CommandButton cdmDelete 
      Caption         =   "&Delete"
      Height          =   375
      Left            =   120
      TabIndex        =   5
      Top             =   840
      Width           =   1215
   End
   Begin VB.CommandButton cmdRename 
      Caption         =   "&Rename"
      Height          =   375
      Left            =   1560
      TabIndex        =   4
      Top             =   840
      Width           =   1215
   End
   Begin VB.CommandButton cmdContinue 
      Caption         =   "&Ignore"
      Height          =   375
      Left            =   4440
      TabIndex        =   3
      Top             =   840
      Width           =   1215
   End
   Begin VB.TextBox txtDest 
      Height          =   285
      Left            =   1440
      TabIndex        =   1
      Text            =   "C:\<game name> logs"
      Top             =   1320
      Width           =   1935
   End
   Begin VB.CommandButton cmdMove 
      Caption         =   "&Move To"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   1320
      Width           =   1215
   End
   Begin VB.Line Line1 
      X1              =   3360
      X2              =   3480
      Y1              =   1320
      Y2              =   1560
   End
   Begin VB.Label lblCaption 
      Caption         =   "A 'qconsole.log' file already exsist in <dir> Would you like this file to be deleted?"
      Height          =   495
      Left            =   240
      TabIndex        =   2
      Top             =   120
      Width           =   5295
   End
End
Attribute VB_Name = "frmLogFound"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const LogFile As String = "qconsole.log"
Dim DefLog As String
Private Sub cdmDelete_Click()
On Error Resume Next
If Exists(LogDir & "\" & LogFile) Then
    Kill LogDir & "\" & LogFile
    If Err Then
        MsgBox "Unable to delete " & LogFile & "!", vbCritical, "Can't Delete Log File"
        OKContinue = False
        Unload Me
    End If
End If
Unload Me
End Sub

Private Sub cmdCancel_Click()
OKContinue = False
Unload Me
End Sub

Private Sub cmdContinue_Click()
Unload Me
End Sub


Private Sub cmdMove_Click()
On Error Resume Next

If txtDest.Text = "" Then
    MsgBox "You need to enter a destionation directory", vbInformation
    txtDest.SetFocus
    Exit Sub
End If

If txtFileName.Text = "" Then
    MsgBox "You need to enter a file name", vbInformation
    txtFileName.SetFocus
    Exit Sub
End If

'append .log
If Not LCase(txtFileName.Text) Like "*.log" Then
    txtFileName.Text = txtFileName.Text & ".log"
End If

'check if file exists
If Exists(txtDest.Text & "\" & txtFileName.Text) Then
    If MsgBox(LogFile & " already exists in " & txtDest & vbCrLf & "Do you want to overwrite it?", vbYesNo + vbQuestion, "Overwrite file?") = vbNo Then
        Exit Sub
    End If
End If
    
'check if dir exists, if not then attempt to make it
If Not Exists(txtDest.Text) Then
    MkDir txtDest.Text
    If Err Then
        MsgBox "Unable to move " & LogFile & vbCrLf & "The destination directory must exist", vbCritical, "Unable to move file"
        Exit Sub
    End If
End If

'copy file and give error output if needed
FileCopy LogDir & "\" & LogFile, txtDest.Text & "\" & txtFileName.Text
If Err Then
    MsgBox "Unable to move " & LogFile & vbCrLf & "Please make sure that the destion is not full", vbCritical, "Unable to move file"
    Exit Sub
End If

'delete old file
Kill LogDir & "\" & LogFile
If Err Then
    MsgBox "Unable to move " & LogFile & vbCrLf & "Please make sure the file is not in use", vbCritical, "Unable to move file"
    Exit Sub
End If

Unload Me
End Sub

Private Sub cmdRename_Click()
Dim NewFile As String

On Error Resume Next

NewFile = InputBox("Enter new file name for" & LogFile, "Enter new file name", DefLog)
'append .log if needed
If Not LCase(NewFile) Like "*.log" Then
    NewFile = NewFile & ".log"
End If

'check if names the same
If NewFile = LogFile Then
    MsgBox "You need to enter a diffrent name", vbInformation
    Exit Sub
End If

'rename and give err output if needed
Name LogDir & "\" & LogFile As LogDir & "\" & NewFile
If Err Then
    MsgBox "Error reanming file", vbCritical
    OKContinue = False
    Unload Me
End If

Unload Me
End Sub


Private Sub Form_Load()
    If LogDir = "" Then
        Unload Me
    End If
    
    If Not Exists(LogDir & "\" & LogFile) Then
        Unload Me
    End If
    
    SetCaptions
End Sub



Public Sub GetDefLogName()
'get file date & time
DefLog = FileDateTime(LogDir & "\" & LogFile)
'replace all / with - for file name
DefLog = ReplaceText(DefLog, "/", "-")
'take off time (xx:xx:xx) - it's after the space
DefLog = TrimRight(DefLog, InStr(DefLog, " "))
DefLog = GameName & " Log (" & DefLog & ").log"
End Sub

Public Sub SetCaptions()
    GetDefLogName
    txtFileName.Text = DefLog
    txtDest.Text = GetSetting(App.Title, "Settings", "Log File Dir", "C:\" & Trim(GameName) & " logs")
    Me.Caption = "QConsole.log file already in " & LogDir
    lblCaption.Caption = "A 'qconsole.log' file already exsist in " & LogDir & ". What do you want to do with this file?"
    
End Sub

Private Sub Form_Unload(Cancel As Integer)
    SaveSetting App.Title, "Settings", "Log File Dir", txtDest.Text
End Sub


